package com.supermap.search.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.supermap.search.R;
import com.supermap.search.Url_name;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wyw on 2017/3/2.
 */

public class UserActivity extends AppCompatActivity {
    @BindView(R.id.user_enter)
    ImageView userEnter;
    @BindView(R.id.user_name)
    TextView userName;
    @BindView(R.id.user_img)
    ImageView userImg;
    @BindView(R.id.tv_weishangchuancaiji)
    TextView tvWeishangchuancaiji;
    @BindView(R.id.im_weishangchuancaiji)
    ImageView imWeishangchuancaiji;
    @BindView(R.id.weishangchuancaiji)
    RelativeLayout weishangchuancaiji;
    @BindView(R.id.ziyuanliebiao)
    LinearLayout ziyuanliebiao;
    @BindView(R.id.caiji)
    LinearLayout caiji;
    @BindView(R.id.tv_weishangchuanxunjian)
    TextView tvWeishangchuanxunjian;
    @BindView(R.id.im_weishangchuanxunjian)
    ImageView imWeishangchuanxunjian;
    @BindView(R.id.weishangchuanxunjian)
    RelativeLayout weishangchuanxunjian;
    @BindView(R.id.tv_xunjianrenwu)
    TextView tvXunjianrenwu;
    @BindView(R.id.im_xunjianrenwu)
    ImageView imXunjianrenwu;
    @BindView(R.id.xunjianrenwu)
    RelativeLayout xunjianrenwu;
    @BindView(R.id.xunjianjilu)
    LinearLayout xunjianjilu;
    @BindView(R.id.xunjianguiji)
    LinearLayout xunjianguiji;
    @BindView(R.id.xunjian)
    LinearLayout xunjian;
    @BindView(R.id.tv_weishangchuanweixiu)
    TextView tvWeishangchuanweixiu;
    @BindView(R.id.im_weishangchuanweixiu)
    ImageView imWeishangchuanweixiu;
    @BindView(R.id.weishangchuanweixiu)
    RelativeLayout weishangchuanweixiu;
    @BindView(R.id.tv_weixiurenwu)
    TextView tvWeixiurenwu;
    @BindView(R.id.im_weixiurenwu)
    ImageView imWeixiurenwu;
    @BindView(R.id.weixiurenwu)
    RelativeLayout weixiurenwu;
    @BindView(R.id.weixiujilu)
    LinearLayout weixiujilu;
    @BindView(R.id.weixiu)
    LinearLayout weixiu;
    @BindView(R.id.tv_weishangchuanyanzheng)
    TextView tvWeishangchuanyanzheng;
    @BindView(R.id.im_weishangchuanyanzheng)
    ImageView imWeishangchuanyanzheng;
    @BindView(R.id.weishangchuanyanzheng)
    RelativeLayout weishangchuanyanzheng;
    @BindView(R.id.tv_yanzheng)
    TextView tvYanzheng;
    @BindView(R.id.im_yanzheng)
    ImageView imYanzheng;
    @BindView(R.id.yanzhengrenwu)
    RelativeLayout yanzhengrenwu;
    @BindView(R.id.yanzhengjilu)
    LinearLayout yanzhengjilu;
    @BindView(R.id.yanzheng)
    LinearLayout yanzheng;
    private SharedPreferences sp;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
//        初始化巡检dao
        sp = getSharedPreferences(Url_name.SP, 0);
    }


    private void xiaotieshi() {
        Intent intent = new Intent(UserActivity.this, XiaoTieShiActivity.class);
        startActivity(intent);
    }


    private void xunJianJiLu() {
        Intent intent = new Intent(UserActivity.this, XunJianJiLuActivity.class);
        startActivity(intent);
    }

    private void taiJiaUser() {
        if (sp.getBoolean("state", false)) {
//            登陆了,注销操作
            sp.edit().putBoolean("state", false).commit();
            sp.edit().putString("name", "").commit();
            userName.setText("未登陆");
            userImg.setBackgroundResource(R.mipmap
                    .denglu);
        } else {
//            没有登陆了，登陆操作
            Intent intent = new Intent(UserActivity.this, LoginActivity.class);
            startActivity(intent);
        }
    }

    private void weishangchuanxunjian() {
        Intent intent = new Intent(UserActivity.this, NoUpXunJianActivity.class);
        startActivity(intent);
    }

    private void checkUser() {
        if (sp.getBoolean("state", false)) {
//            登陆了
            userName.setText(sp.getString("name", ""));
            userImg.setBackgroundResource(R.mipmap.zhuxiao);
        } else {
//            没有登陆了
            userName.setText("未登陆");
            userImg.setBackgroundResource(R.mipmap.denglu);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        checkUser();
    }

    @OnClick({R.id.user_img,R.id.weishangchuancaiji, R.id.ziyuanliebiao,R.id.weishangchuanxunjian, R.id.xunjianrenwu, R.id.xunjianjilu, R.id.xunjianguiji, R.id.weishangchuanweixiu, R.id.weixiurenwu, R.id.weixiujilu, R.id.weishangchuanyanzheng, R.id.yanzhengrenwu, R.id.yanzhengjilu})
    public void onViewClicked(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.user_img:
                intent = new Intent(UserActivity.this, LoginActivity.class);
                startActivity(intent);
                break;
            case R.id.weishangchuancaiji:
                intent = new Intent(UserActivity.this, NoUpCollectActivity.class);
                startActivity(intent);
                break;
            case R.id.ziyuanliebiao:
                intent = new Intent(UserActivity.this, ZiYuanListActivity.class);
                startActivity(intent);
                break;
            case R.id.weishangchuanxunjian:
                intent = new Intent(UserActivity.this, NoUpXunJianActivity.class);
                startActivity(intent);
                break;
            case R.id.xunjianrenwu:
                intent = new Intent(UserActivity.this, XunJianTaskActivity.class);
                startActivity(intent);
                break;
            case R.id.xunjianjilu:
                intent = new Intent(UserActivity.this, XunJianJiLuActivity.class);
                startActivity(intent);
                break;
            case R.id.xunjianguiji:

                break;
            case R.id.weishangchuanweixiu:
                intent = new Intent(UserActivity.this, NoUpWeiXiuActivity.class);
                startActivity(intent);
                break;
            case R.id.weixiurenwu:
                intent = new Intent(UserActivity.this, WeiXiuTaskActivity.class);
                startActivity(intent);
                break;
            case R.id.weixiujilu:
                intent = new Intent(UserActivity.this, WeiXiuJiLuActivity.class);
                startActivity(intent);
                break;
            case R.id.weishangchuanyanzheng:
                intent = new Intent(UserActivity.this, NoUpYanZhengActivity.class);
                startActivity(intent);
                break;
            case R.id.yanzhengrenwu:
                intent = new Intent(UserActivity.this, YanZhengTaskActivity.class);
                startActivity(intent);
                break;
            case R.id.yanzhengjilu:
                intent = new Intent(UserActivity.this, YanZhengJiluActivity.class);
                startActivity(intent);
                break;
        }
    }
}
